//
//  HRZCenterServiceCell.m
//  EMarket
//
//  Created by 石头 on 2018/5/16.
//  Copyright © 2018年 好日子. All rights reserved.
//

#import "HRZCenterServiceCell.h"

#import "HRZGridCell.h"

@interface HRZCenterServiceCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (weak, nonatomic) IBOutlet UIView *topTitleView;

/* collectioView */
@property (strong , nonatomic)UICollectionView *collectionView;

@end

static NSString * const HRZGridCellID = @"HRZGridCell";

@implementation HRZCenterServiceCell

#pragma mark - LoadLazy
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *dcFlowLayout = [UICollectionViewFlowLayout new];
        dcFlowLayout.minimumLineSpacing = dcFlowLayout.minimumInteritemSpacing = 0;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:dcFlowLayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        
        [_collectionView registerClass:[HRZGridCell class] forCellWithReuseIdentifier:HRZGridCellID];
        
        [self addSubview:_collectionView];
    }
    return _collectionView;
}


#pragma mark - Intial
- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backgroundColor = [UIColor clearColor];
    self.collectionView.backgroundColor = [UIColor whiteColor];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(self);
        [make.bottom.mas_equalTo(self)setOffset:-HRZMargin];
        make.top.mas_equalTo(self->_topTitleView.mas_bottom);
    }];
    
}

#pragma mark - <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _serviceItemArray.count;
}

#pragma mark - <UICollectionViewDelegate>
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HRZGridCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:HRZGridCellID forIndexPath:indexPath];
    
    cell.gridItem = _serviceItemArray[indexPath.row];
    
    return cell;
}

#pragma mark - <UICollectionViewDelegateFlowLayout>
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(kScreenWidth / 4, 85);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(delegateTableCell:didSelectedItemAtIndexPath:)]) {
        [self.delegate delegateTableCell:self didSelectedItemAtIndexPath:indexPath];
    }
}


@end
